package com.chenjiaru.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/producer")
@Slf4j
public class TestProducerController {


    @Value("${spring.kafka.topic.t1}")
    private String t1;

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @RequestMapping("/send")
    public String send(String message) {
        // 发送消息
        kafkaTemplate.send(t1, "test-key", message);
        log.info("发送成功:{}",message);
        return message;
    }

}
